/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package elementsDefense.towers;

import elementsDefense.towers.projectils.Canonball;
import com.jme3.asset.AssetManager;
import com.jme3.effect.ParticleEmitter;
import com.jme3.effect.ParticleMesh;
import com.jme3.material.Material;
import com.jme3.math.ColorRGBA;
import com.jme3.math.FastMath;
import com.jme3.math.Quaternion;
import com.jme3.math.Vector3f;
import com.jme3.scene.Geometry;
import com.jme3.scene.Node;
import com.jme3.scene.Spatial;
import com.jme3.scene.shape.Sphere;
import elementsDefense.enemies.BasicEnemy;
import elementsDefense.towers.projectils.Thunder;

/**
 *
 * @author Ricardo
 */
public class ThunderTower extends Tower{
    static Material matTower;
    static Material matBall;
    private Geometry geom2;
    
    public void build(AssetManager assetManager, Node node, Vector3f location){
        super.build(assetManager, node, location);
        if(matTower==null){
            matTower = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
            matTower.setTexture("ColorMap", assetManager.loadTexture("Textures/tower_thunder.jpg"));
            
            matBall = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
            matBall.setTexture("ColorMap", assetManager.loadTexture("Textures/static.jpg"));
        }
        geom = assetManager.loadModel("Models/tower_thunder.j3o");
//        geom.rotate(0, FastMath.HALF_PI, 0);
        geom.setMaterial(matTower);
        node.attachChild(geom);
        this.fireLocation = new Vector3f(location).add(0, 0.80f, 0);
        geom.setLocalTranslation(location);
        
        searchAndDestroy = new SearchAndDestroyControl(3, 2f, 0.5f, this);
        geom.addControl(searchAndDestroy);
        
        geom2=new Geometry("staticBall", new Sphere(10, 10, 0.23f));
        geom2.setMaterial(matBall);
        geom2.setLocalRotation(new Quaternion(new float[]{FastMath.HALF_PI,0,0}));
        geom2.setLocalTranslation(fireLocation);
        geom2.setLocalScale(0);
        node.attachChild(geom2);
        
    }

    void prepareToFire(BasicEnemy enemy, float animPhase){
        geom2.setLocalScale(0.95f+FastMath.sin(animPhase)/20);
        geom2.rotate(0, 0, animPhase);
    }
    
    void fire(BasicEnemy enemy){
        geom2.setLocalScale(0);
        //fire projectil
        new Thunder(assetManager, node, this).shootAt(enemy);
    }

    @Override
    int getCost() {
        return 70;
    }
  
}
